<template>
  <div>
    <van-nav-bar title="发布" />
    <van-cell-group>
      <van-field v-model="content" rows="2" autosize type="textarea" placeholder="请输入内容..." show-word-limit />
    </van-cell-group>
    <h3 style="margin: 20px;">内容类型</h3>
    <van-dropdown-menu active-color="#1989fa" style="margin: 20px;">
      <van-dropdown-item v-model="value" :options="option" />
    </van-dropdown-menu>

    <!-- 发布图片 -->
    <!-- <div style="margin: 20px 5px;">
      <van-uploader v-model="fileList" multiple />
    </div> -->

    <van-button class="send" type="info" @click="send(uid, content, value)">发布</van-button>
  </div>
</template>

<script>
import { Toast } from 'vant';
import { contentAPI, getClassAPI } from '../api/API'
export default {
  name: 'Send',
  data() {
    return {
      content: "",
      uid: "",
      option: [
        {
          text: '分类1',
          value: 1
        },
        {
          text: '分类2',
          value: 2
        },
        {
          text: '分类3',
          value: 3
        },
      ],
      // 分类id
      value: 1,
    }
  },
  methods: {
    send(uid, content, value) {
      // console.log(this.fileList);
      if (this.content.trim() == '') {
        return Toast.fail('内容不能为空!');
      }
      // 发布
      contentAPI(uid, content, value).then((res) => {
        console.log(res);
        if (res.data.code === 200) {
          Toast.success(res.data.date);
          this.content = ''
        } else if (res.data.code === 400) {
          Toast.fail(res.data.date);
        }
      })
    }
  },
  mounted() {
    this.uid = localStorage.getItem('userID')
    getClassAPI().then((res) => {
      console.log(res.data.date);
    })
  }
}
</script>

<style>
.send {
  position: absolute;
  bottom: 10vh;
  width: 90%;
  margin: 0 5%;
  border-radius: 15px;
}
</style>